//
//  ViewController.swift
//  TXiOSDemoApp
//
//  Created by xicheng on 16/11/17.
//  Copyright © 2016年 xicheng. All rights reserved.
//

import UIKit

class ViewController: TXBaseViewController {

  fileprivate var tableView:UITableView! = nil
  fileprivate var adapter:DemoAdapter! = nil
  override func initView() {
    self.naviBar.title = "天唐iOS—Demo"
    
    self.tableView = UITableView(frame: self.view.bounds)
    self.tableView.contentInset = UIEdgeInsets(top: kNaviHeight, left: 0, bottom: 0, right: 0)
    self.view.addSubview(self.tableView)
    self.adapter = DemoAdapter(vc: self)
    self.adapter.setupTableView(tableView: self.tableView)
    self.tableView.separatorStyle = .singleLine
  }
  
  
  override func initData() {
    self.adapter.refreshCount(listData: ["SingleButtonViewController","ProgressManagerViewController","AdapterViewController","DaoViewController"])
  }

}

extension ViewController{
  
  override func needShowProgress() -> Bool {
    return false
  }

  override func leftBarButton() -> UIButton? {
    return nil
  }
  
}


class DemoAdapter :BaseAdapter<String,UITableViewCell,ViewController>{

  
  
  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
    guard let targetVC = self.targetVC ,let vcName = self.dataList?[indexPath.row] else {
      return
    }
    
    if let vcType = NSClassFromString("TXiOSDemoApp.\(vcName)") as? TXBaseViewController.Type {
      let vc = vcType.init()
      targetVC.pushVC(vc)
    }
   
  }
  
  override func setupCell(_ tableView: UITableView, cell: UITableViewCell, model: String, indexPath: IndexPath) {
    cell.textLabel?.text = model
  }
  
  override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 54
  }
  
  override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
    return true
  }
  
  
}
